<?php
echo $this->headLink()->prependStylesheet($this->baseUrl().'/css/cep_index.css');
echo $this->headLink()->prependStylesheet($this->baseUrl().'/css/datatables/demo_page.css');
echo $this->headLink()->prependStylesheet($this->baseUrl().'/css/datatables/demo_table_jui.css');
echo $this->headLink()->prependStylesheet($this->baseUrl().'/css/datatables/demo_table.css');
echo $this->headLink()->prependStylesheet($this->baseUrl().'/css/ui-darkness/jquery-ui-1.8.16.custom.css');
echo $this->headScript()->appendFile($this->baseUrl().'/js/jquery-1.6.2.min.js');
echo $this->headScript()->appendFile($this->baseUrl().'/js/jquery-ui-1.8.16.custom.min.js');
echo $this->headScript()->appendFile($this->baseUrl().'/js/datatables/jquery.dataTables.min.js');
?>
<script type="text/javascript">
$(document).ready(function(){
	$('#table1').dataTable( {
		"bJQueryUI": true
	});
	$('#table2').dataTable( {
		"bJQueryUI": true
	});
});
$(function() {
	$("#datepicker1").datepicker({dateFormat: 'yy-mm-dd'});
});
$(function() {
	$("#datepicker2").datepicker({dateFormat: 'yy-mm-dd'});
});
</script>
<?php
$this->title = "Prepare CDR";
$this->headTitle($this->title);
?>
<h1><a href="<?php echo $this->url(array('controller'=>'index', 'action'=>'index'), null, true); ?>">Home</a> > <?php echo $this->escape($this->title); ?></h1>
<div class="cont">
<?php echo $this->form; ?>
<div class="gap"></div>
<div class="table">
<table id="table1">
<thead>
<tr>
	<th>CEP No</th>
	<th>CEP date</th>
	<th>CEP Description</th>
	<th>Product Number</th>
	<th>Staff Number</th>
	<th>Customer Number</th>
	<th>Department Name</th>
</tr>
</thead>
<tbody>
<?php if (isset($this->ceps)) { 
foreach($this->ceps as $cep) :
?>
<tr>
	<td><?php echo $this->escape($cep->cep_no); ?></td>
	<td><?php echo $this->escape($cep->cep_date); ?></td>
	<td><?php echo $this->escape($cep->cep_description); ?></td>
	<td><a href="<?php echo $this->url(array('controller'=>'cep', 'action'=>'index', 'prod_no' => $cep->prod_no, 'show_detail'=>'yes'))?>"><?php echo $this->escape($cep->prod_no); ?></a></td>
	<td><?php echo $this->escape($cep->staff_no); ?></td>
	<td><?php echo $this->escape($cep->cust_no); ?></td>
	<td><?php echo $this->escape($cep->dep_name); ?></td>
</tr>
<?php endforeach; } ?>
</tbody>
</table>
</div>
<div class="gap"></div>

<?php if($this->show == "yes") { ?>
<div class="table">
<table id="table2">
<thead>
<tr>
	
	<th>Product Number</th>
	<th>Name</th>
	<th>Colour</th>
	<th>Size</th>
	<th>Price</th>
	<th>Out of stock</th>
	<th>Not a Stocked Item</th>
	<th>Department Name</th>
</tr>
</thead>
<tbody>
<?php
	$price = 0;
	$outStock = 0;
	$notStock = 0;
	$dep_name;
	foreach($this->products as $prod)
	{
		$prod_no = $prod->prod_no;
		$desc = $prod->cep_description;
		$dep_name = $prod->dep_name;
		if($desc == "Out of Stock")
		{
			$outStock++;
		}
		else if($desc == "Not a Stocked Item")
		{
			$notStock++;
		}
		else if($desc == "Price")
		{
			$price++;
		}
	}	
	if($prod_no){
		$product = new Application_Model_DbTable_Products();
	  	$selectName = $product->select()
	  		->where('prod_no = ?', $prod_no);
	  	$name = $product->fetchRow($selectName);
	}
?>
<tr>
	<td><?php echo $prod_no; ?></td>
	<td><?php if ($name->prod_name) { echo $name->prod_name; } else { echo "None"; } ?></td>
	<td><?php if ($name->prod_colour) { echo $name->prod_colour; } else { echo "None"; } ?></td>
	<td><?php if ($name->prod_size) { echo $name->prod_size; } else { echo "None"; } ?></td>
	<td><?php if($prod_no != null) { echo $price; } ?></td>
	<td><?php if($prod_no != null) { echo $outStock; } ?></td>
	<td><?php if($prod_no != null) { echo $notStock; } ?></td>
	<td><?php echo $dep_name; ?></td>
</tr>
</tbody>
</table>
</div>
<?php }?>
</div>
